from aioredis import ConnectionsPool
import pytest
from aiomysql import Pool
from asgi_lifespan import LifespanManager
from fastapi import FastAPI
from httpx import AsyncClient


@pytest.fixture
def pool(initialized_app: FastAPI) -> Pool:
    return initialized_app.state.pool


@pytest.fixture
def redis(initialized_app: FastAPI) -> ConnectionsPool:
    return initialized_app.state.redis


@pytest.fixture
def app() -> FastAPI:
    from main import create_app
    return create_app()


@pytest.fixture
async def initialized_app(app: FastAPI) -> FastAPI:
    async with LifespanManager(app):
        yield app


@pytest.fixture
async def client(initialized_app: FastAPI) -> AsyncClient:
    async with AsyncClient(
            app=initialized_app,
            base_url='http://testserver',
            headers={'Content-Type': 'application/json'}
    ) as client:
        yield client
